import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

enum ToastState { success, fail, warning }

class CustomToastWidget extends StatefulWidget {
  final CancelFunc? cancelFunc;
  final ToastState? state;
  final String? contentText;

  const CustomToastWidget(
      {Key? key, this.cancelFunc, this.state, this.contentText})
      : super(key: key);

  @override
  CustomToastWidgetState createState() => CustomToastWidgetState();
}

class CustomToastWidgetState extends State<CustomToastWidget>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child:
          widget.state == ToastState.success ? _setupSuccess() : _setupOther(),
    );
  }

  Widget _setupSuccess() {
    return Card(
      color: Colors.black,
      child: Padding(
        padding: EdgeInsets.fromLTRB(26.w, 18.w, 26.w, 18.w),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            SvgPicture.asset(
              'assets/svg/ic_toast_succeed_line.svg',
              width: 48.w,
              height: 48.w,
            ),
            Container(
              margin: EdgeInsets.fromLTRB(0, 8.w, 0, 0),
              child: Text(
                widget.contentText ?? "",
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16.sp, color: Colors.white),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _setupOther() {
    return Card(
      color: Colors.black,
      child: Padding(
        padding: EdgeInsets.all(18.0.w),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            SvgPicture.asset(
              widget.state == ToastState.warning
                  ? 'assets/svg/ic_toast_warning.svg'
                  : 'assets/svg/ic_toast_clean.svg',
              width: 22.w,
              height: 22.w,
            ),
            Container(
              margin: EdgeInsets.fromLTRB(0, 12.w, 0, 0),
              width: 210.w,
              child: Text(
                widget.contentText ?? "",
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 16.sp,
                  color: Colors.white,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
